import React, { useState } from 'react'
import { useEffect } from 'react'

export default function App() {
  let [person,setPerson] = useState([{
    id:1,
    name:'张三',
  },{
    id:2,
    name:'李四',
  },{
    id:3,
    name:'王五',
}]);

useEffect(() => {
  console.log('person改变了');
},[person]);

const addPerson = () => {
  setPerson([...person,{id:Date.now(),name:'♥♥♥'}]);
}

  return (
    <div>
      <button onClick={addPerson}>添加数据</button>
      <ul>
        {
        person.map(item => {
          return <li key={item.id}>{item.name}</li>
        })
        }
      </ul>
      
    </div>
  )
}
 